package com.mdxx.xczd.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mdxx.xczd.R;
import com.mdxx.xczd.widget.TimerTextView;

public class DialogUtil {

	/**
	 *任务开始提醒
	 */
	public  static void taskBeginDialog(Context context,String route, String time, String endTime,OnClickListener listener) {
		long[] times = FormatUtil.getTimeDif(endTime);
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_task_begin, null);			
		TextView tv_dialog_task_route = (TextView)layout.findViewById(R.id.tv_dialog_task_route);
		TextView tv_dialog_task_begintime = (TextView)layout.findViewById(R.id.tv_dialog_task_begintime);
		tv_dialog_task_route.setText("任务路线："+route);
		tv_dialog_task_begintime.setText("任务时间："+time);
		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); 
		p.height = (int) ((int) ScreenUtil.getScreenHeight()*0.6);
	    p.width = (int) (ScreenUtil.getScreenWith()*0.8);
		dialog.getWindow().setAttributes(p); 
		p.gravity = Gravity.CENTER;
		layout.findViewById(R.id.btn_dialog_center).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dialog.dismiss();
			}
		});
		dialog.show();
	}
	
	/**
	 *新任务提醒
	 */
	public static void newTaskDialog(Context context,String route, String time, OnClickListener listener) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_new_task, null);			
		TextView tv_dialog_newtask_route = (TextView)layout.findViewById(R.id.tv_dialog_newtask_route);
		TextView tv_dialog_newtask_time = (TextView)layout.findViewById(R.id.tv_dialog_newtask_time);
		tv_dialog_newtask_route.setText("任务路线："+route);
		tv_dialog_newtask_time.setText("任务时间："+time);
		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
		p.height = (int) ((int) ScreenUtil.getScreenHeight()*0.6);
		p.width = (int) (ScreenUtil.getScreenWith()*0.8);
		p.gravity = Gravity.CENTER;
		dialog.getWindow().setAttributes(p); 
		layout.findViewById(R.id.btn_dialog_left).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dialog.dismiss();
			}
		});
		dialog.show();
	}
	
	/**
	 *任务完成提醒
	 */
	public  static void taskFinishDialog(Context context,String route, String time, String notice,OnClickListener listener) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_task_finished, null);			
		TextView tv_dialog_taskfinish_route = (TextView)layout.findViewById(R.id.tv_dialog_taskfinish_route);
		TextView tv_dialog_taskfinish_time = (TextView)layout.findViewById(R.id.tv_dialog_taskfinish_time);
		TextView tv_dialog_taskfinish_time2 = (TextView)layout.findViewById(R.id.tv_dialog_taskfinish_time2);
		tv_dialog_taskfinish_route.setText("任务路线："+route);
		tv_dialog_taskfinish_time.setText("任务时间："+time);
		tv_dialog_taskfinish_time2.setText("实际用时："+notice);		
		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
		p.height = (int) ((int) ScreenUtil.getScreenHeight()*0.6);
		p.width = (int) (ScreenUtil.getScreenWith()*0.8);
		p.gravity = Gravity.CENTER;
		dialog.getWindow().setAttributes(p); 
		dialog.show();
	}
	
	/**
	 *任务加时
	 */
	private  static void taskOverTimeDialog(Context context,String route, String time, String overtime,OnClickListener listener) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_task_overtime, null);			
		TextView tv_dialog_overtime_route = (TextView)layout.findViewById(R.id.tv_dialog_overtime_route);
		TextView tv_dialog_taskfinish_time = (TextView)layout.findViewById(R.id.tv_dialog_overtime_tasktime);
		TextView tv_dialog_overtime_time = (TextView)layout.findViewById(R.id.tv_dialog_overtime_time);
		tv_dialog_overtime_route.setText("任务路线："+route);
		tv_dialog_taskfinish_time.setText("任务时间："+time);
		tv_dialog_overtime_time.setText("任务加时："+overtime);		
		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
		p.height = (int) ((int) ScreenUtil.getScreenHeight()*0.6);
		p.width = (int) (ScreenUtil.getScreenWith()*0.8);
		p.gravity = Gravity.CENTER;
		dialog.getWindow().setAttributes(p); 
		p.gravity = Gravity.CENTER;		
		dialog.show();
	}
	
	/**
	 *任务加时
	 */
	private  static void aa(Context context,String route, String time, String overtime,OnClickListener listener) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_task_overtime, null);			
		TextView tv_dialog_overtime_route = (TextView)layout.findViewById(R.id.tv_dialog_overtime_route);
		TextView tv_dialog_taskfinish_time = (TextView)layout.findViewById(R.id.tv_dialog_overtime_tasktime);
		TextView tv_dialog_overtime_time = (TextView)layout.findViewById(R.id.tv_dialog_overtime_time);
		tv_dialog_overtime_route.setText("任务路线："+route);
		tv_dialog_taskfinish_time.setText("任务时间："+time);
		tv_dialog_overtime_time.setText("任务加时："+overtime);		
		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
		p.height = (int) ((int) ScreenUtil.getScreenHeight()*0.6);
		p.width = (int) (ScreenUtil.getScreenWith()*0.8);
		p.gravity = Gravity.CENTER;
		dialog.getWindow().setAttributes(p); 
		p.gravity = Gravity.CENTER;		
		dialog.show();
	}


	public static void amartmateDialog(final Context context) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_amartmate, null);

		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
		p.height = (int) ((int) ScreenUtil.getScreenHeight()*0.3);
		p.width = (int) (ScreenUtil.getScreenWith()*0.8);
		p.gravity = Gravity.CENTER;
		dialog.getWindow().setAttributes(p);
		layout.findViewById(R.id.btn_on).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setAction("com.smartmate.action.POWER_ON");
				context.sendBroadcast(intent);
				dialog.dismiss();
			}
		});
		layout.findViewById(R.id.btn_off).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent2 = new Intent();
				intent2.setAction("com.smartmate.action.POWER_OFF");
				context.sendBroadcast(intent2);
				dialog.dismiss();
			}
		});
		dialog.show();
	}
	
	/*private void chatDialog(Context context, List<String> list) {
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.dialog_chat, null);	
		TextView groupName = (TextView)layout.findViewById(R.id.tv_dialog_talk_location);
		ListView listview = (ListView)layout.findViewById(R.id.list_dialog_talk);
		TalkBackAdapter adapter = new TalkBackAdapter(context, list);
		listview.setAdapter(adapter);
		final Dialog dialog = new Dialog(context,R.style.dialog);
		dialog.setContentView(layout);
		dialog.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); 		
		p.height = (int) (App.HEIGHT_WIN*0.6);
	    p.width = (int) (App.WIDTH_WIN*0.8);
		p.gravity = Gravity.CENTER;
		dialog.getWindow().setAttributes(p); 	
		dialog.show();
	}*/
}
